package com.hckj.jianzhijia.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVUser;
import com.hckj.jianzhijia.R;
import com.hckj.jianzhijia.model.NormalUser;
import com.hckj.jianzhijia.views.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by 赵奇隆 on 2015-12-05.
 */
public class EnrollPeopleListAdapter extends BaseAdapter {


    private Context context;
    private LayoutInflater mInflater;
    private ArrayList<NormalUser> list;


    public EnrollPeopleListAdapter(Context context, ArrayList<NormalUser> list) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        this.list = list;
    }



    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        NormalUser normalUser = list.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_enroll_people, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if( normalUser.getPic() == null){
            viewHolder.imgvUserPic.setImageResource(R.drawable.icon_default_head_pic);
        }else{
            Picasso.with(context).load(normalUser.getPic().getUrl()).into(viewHolder.imgvUserPic);
        }
        viewHolder.tvUserName.setText(normalUser.getName());
        viewHolder.tvPhone.setText(normalUser.getUsername());

        return convertView;
    }


    class ViewHolder {

        RoundImageView imgvUserPic;
        TextView tvUserName;
        TextView tvPhone;

        ViewHolder(View view) {
            this.imgvUserPic = (RoundImageView) view.findViewById(R.id.imgv_user_pic);
            this.tvUserName = (TextView) view.findViewById(R.id.tv_user_name);
            this.tvPhone = (TextView) view.findViewById(R.id.tv_phone);
        }
    }







}

